import React from 'react';
import { Router as DefaultRouter, Route, Switch } from 'react-router-dom';
import dynamic from 'umi/dynamic';
import renderRoutes from 'umi/lib/renderRoutes';
import history from '@tmp/history';
import { routerRedux, dynamic as _dvaDynamic } from 'dva';

const Router = routerRedux.ConnectedRouter;

const routes = [
  {
    path: '/system/group',
    redirect: '/system/group/roles',
    exact: true,
    _title: '四川省农业信贷智能担保综合管理平台',
    _title_default: '四川省农业信贷智能担保综合管理平台',
  },
  {
    path: '/system',
    redirect: '/system/user',
    exact: true,
    _title: '四川省农业信贷智能担保综合管理平台',
    _title_default: '四川省农业信贷智能担保综合管理平台',
  },
  {
    path: '/',
    redirect: '/dashboard',
    exact: true,
    _title: '四川省农业信贷智能担保综合管理平台',
    _title_default: '四川省农业信贷智能担保综合管理平台',
  },
  {
    path: '/login',
    component: __IS_BROWSER
      ? _dvaDynamic({
          component: () => import('../../layouts/LoginLayout'),
        })
      : require('../../layouts/LoginLayout').default,
    routes: [
      {
        path: '/login',
        component: __IS_BROWSER
          ? _dvaDynamic({
              app: require('@tmp/dva').getApp(),
              models: () => [
                import('D:/work/bank/nodejs/app/web/src/pages/login/model.js').then(
                  m => {
                    return { namespace: 'model', ...m.default };
                  },
                ),
              ],
              component: () => import('../login'),
            })
          : require('../login').default,
        exact: true,
        _title: '四川省农业信贷智能担保综合管理平台',
        _title_default: '四川省农业信贷智能担保综合管理平台',
      },
      {
        component: __IS_BROWSER
          ? _dvaDynamic({
              component: () => import('../404'),
            })
          : require('../404').default,
        exact: true,
        _title: '四川省农业信贷智能担保综合管理平台',
        _title_default: '四川省农业信贷智能担保综合管理平台',
      },
      {
        component: () =>
          React.createElement(
            require('D:/work/bank/nodejs/node_modules/umi-build-dev/lib/plugins/404/NotFound.js')
              .default,
            { pagesPath: 'src/pages', hasRoutesInConfig: true },
          ),
        _title: '四川省农业信贷智能担保综合管理平台',
        _title_default: '四川省农业信贷智能担保综合管理平台',
      },
    ],
    _title: '四川省农业信贷智能担保综合管理平台',
    _title_default: '四川省农业信贷智能担保综合管理平台',
  },
  {
    path: '/',
    component: __IS_BROWSER
      ? _dvaDynamic({
          component: () => import('../../layouts/AuthBasicLayout'),
        })
      : require('../../layouts/AuthBasicLayout').default,
    routes: [
      {
        path: '/dashboard',
        name: '首页',
        component: __IS_BROWSER
          ? _dvaDynamic({
              app: require('@tmp/dva').getApp(),
              models: () => [
                import('D:/work/bank/nodejs/app/web/src/pages/dashboard/models/chart.js').then(
                  m => {
                    return { namespace: 'chart', ...m.default };
                  },
                ),
              ],
              component: () => import('../dashboard'),
            })
          : require('../dashboard').default,
        icon: 'home',
        exact: true,
        _title: '四川省农业信贷智能担保综合管理平台',
        _title_default: '四川省农业信贷智能担保综合管理平台',
      },
      {
        path: '/demo',
        component: __IS_BROWSER
          ? _dvaDynamic({
              component: () => import('../../components/Tabs'),
            })
          : require('../../components/Tabs').default,
        name: '演示',
        title: '组件形式合集',
        icon: 'retweet',
        hideMenu: true,
        routes: [
          {
            path: '/demo/a1',
            name: '常规页面',
            icon: 'bank',
            selected: true,
            component: __IS_BROWSER
              ? _dvaDynamic({
                  component: () => import('../demo/demo1'),
                })
              : require('../demo/demo1').default,
            exact: true,
            _title: '组件形式合集',
            _title_default: '四川省农业信贷智能担保综合管理平台',
          },
          {
            path: '/demo/a2',
            name: '弹窗面板集合',
            icon: 'bank',
            component: __IS_BROWSER
              ? _dvaDynamic({
                  component: () => import('../demo/demo2'),
                })
              : require('../demo/demo2').default,
            exact: true,
            _title: '组件形式合集',
            _title_default: '四川省农业信贷智能担保综合管理平台',
          },
          {
            path: '/demo/a3',
            name: '流程面板',
            icon: 'bank',
            component: __IS_BROWSER
              ? _dvaDynamic({
                  component: () => import('../demo/demo3'),
                })
              : require('../demo/demo3').default,
            exact: true,
            _title: '组件形式合集',
            _title_default: '四川省农业信贷智能担保综合管理平台',
          },
          {
            path: '/demo/a4',
            name: '块状布局',
            icon: 'bank',
            component: __IS_BROWSER
              ? _dvaDynamic({
                  component: () => import('../demo/demo4'),
                })
              : require('../demo/demo4').default,
            exact: true,
            _title: '组件形式合集',
            _title_default: '四川省农业信贷智能担保综合管理平台',
          },
          {
            component: () =>
              React.createElement(
                require('D:/work/bank/nodejs/node_modules/umi-build-dev/lib/plugins/404/NotFound.js')
                  .default,
                { pagesPath: 'src/pages', hasRoutesInConfig: true },
              ),
            _title: '四川省农业信贷智能担保综合管理平台',
            _title_default: '四川省农业信贷智能担保综合管理平台',
          },
        ],
        _title: '组件形式合集',
        _title_default: '四川省农业信贷智能担保综合管理平台',
      },
      {
        path: '/system',
        component: __IS_BROWSER
          ? _dvaDynamic({
              component: () => import('../../components/Panel'),
            })
          : require('../../components/Panel').default,
        name: '系统',
        title: '系统管理',
        icon: 'gears',
        routes: [
          {
            path: '/system/user',
            component: __IS_BROWSER
              ? _dvaDynamic({
                  app: require('@tmp/dva').getApp(),
                  models: () => [
                    import('D:/work/bank/nodejs/app/web/src/pages/user/model.js').then(
                      m => {
                        return { namespace: 'model', ...m.default };
                      },
                    ),
                  ],
                  component: () => import('../user'),
                })
              : require('../user').default,
            name: '用户管理',
            icon: 'user',
            selected: true,
            exact: true,
            _title: '系统管理',
            _title_default: '四川省农业信贷智能担保综合管理平台',
          },
          {
            path: '/system/group',
            component: __IS_BROWSER
              ? _dvaDynamic({
                  app: require('@tmp/dva').getApp(),
                  models: () => [
                    import('D:/work/bank/nodejs/app/web/src/pages/group/models/group_role.js').then(
                      m => {
                        return { namespace: 'group_role', ...m.default };
                      },
                    ),
                    import('D:/work/bank/nodejs/app/web/src/pages/group/models/group_user.js').then(
                      m => {
                        return { namespace: 'group_user', ...m.default };
                      },
                    ),
                    import('D:/work/bank/nodejs/app/web/src/pages/group/models/group.js').then(
                      m => {
                        return { namespace: 'group', ...m.default };
                      },
                    ),
                    import('D:/work/bank/nodejs/app/web/src/pages/group/models/role.js').then(
                      m => {
                        return { namespace: 'role', ...m.default };
                      },
                    ),
                    import('D:/work/bank/nodejs/app/web/src/pages/group/models/user.js').then(
                      m => {
                        return { namespace: 'user', ...m.default };
                      },
                    ),
                  ],
                  component: () => import('../group'),
                })
              : require('../group').default,
            name: '部门管理',
            icon: 'sitemap',
            hideMenu: true,
            routes: [
              {
                path: '/system/group/roles',
                component: __IS_BROWSER
                  ? _dvaDynamic({
                      app: require('@tmp/dva').getApp(),
                      models: () => [
                        import('D:/work/bank/nodejs/app/web/src/pages/group/models/group_role.js').then(
                          m => {
                            return { namespace: 'group_role', ...m.default };
                          },
                        ),
                        import('D:/work/bank/nodejs/app/web/src/pages/group/models/group_user.js').then(
                          m => {
                            return { namespace: 'group_user', ...m.default };
                          },
                        ),
                        import('D:/work/bank/nodejs/app/web/src/pages/group/models/group.js').then(
                          m => {
                            return { namespace: 'group', ...m.default };
                          },
                        ),
                        import('D:/work/bank/nodejs/app/web/src/pages/group/models/role.js').then(
                          m => {
                            return { namespace: 'role', ...m.default };
                          },
                        ),
                        import('D:/work/bank/nodejs/app/web/src/pages/group/models/user.js').then(
                          m => {
                            return { namespace: 'user', ...m.default };
                          },
                        ),
                      ],
                      component: () => import('../group/role'),
                    })
                  : require('../group/role').default,
                name: '角色列表',
                selected: true,
                exact: true,
                _title: '系统管理',
                _title_default: '四川省农业信贷智能担保综合管理平台',
              },
              {
                path: '/system/group/users',
                component: __IS_BROWSER
                  ? _dvaDynamic({
                      app: require('@tmp/dva').getApp(),
                      models: () => [
                        import('D:/work/bank/nodejs/app/web/src/pages/group/models/group_role.js').then(
                          m => {
                            return { namespace: 'group_role', ...m.default };
                          },
                        ),
                        import('D:/work/bank/nodejs/app/web/src/pages/group/models/group_user.js').then(
                          m => {
                            return { namespace: 'group_user', ...m.default };
                          },
                        ),
                        import('D:/work/bank/nodejs/app/web/src/pages/group/models/group.js').then(
                          m => {
                            return { namespace: 'group', ...m.default };
                          },
                        ),
                        import('D:/work/bank/nodejs/app/web/src/pages/group/models/role.js').then(
                          m => {
                            return { namespace: 'role', ...m.default };
                          },
                        ),
                        import('D:/work/bank/nodejs/app/web/src/pages/group/models/user.js').then(
                          m => {
                            return { namespace: 'user', ...m.default };
                          },
                        ),
                      ],
                      component: () => import('../group/user'),
                    })
                  : require('../group/user').default,
                name: '用户管理',
                exact: true,
                _title: '系统管理',
                _title_default: '四川省农业信贷智能担保综合管理平台',
              },
              {
                component: () =>
                  React.createElement(
                    require('D:/work/bank/nodejs/node_modules/umi-build-dev/lib/plugins/404/NotFound.js')
                      .default,
                    { pagesPath: 'src/pages', hasRoutesInConfig: true },
                  ),
                _title: '四川省农业信贷智能担保综合管理平台',
                _title_default: '四川省农业信贷智能担保综合管理平台',
              },
            ],
            _title: '系统管理',
            _title_default: '四川省农业信贷智能担保综合管理平台',
          },
          {
            path: '/system/role',
            component: __IS_BROWSER
              ? _dvaDynamic({
                  app: require('@tmp/dva').getApp(),
                  models: () => [
                    import('D:/work/bank/nodejs/app/web/src/pages/role/models/auth.js').then(
                      m => {
                        return { namespace: 'auth', ...m.default };
                      },
                    ),
                    import('D:/work/bank/nodejs/app/web/src/pages/role/models/role_auth.js').then(
                      m => {
                        return { namespace: 'role_auth', ...m.default };
                      },
                    ),
                    import('D:/work/bank/nodejs/app/web/src/pages/role/models/role_user.js').then(
                      m => {
                        return { namespace: 'role_user', ...m.default };
                      },
                    ),
                    import('D:/work/bank/nodejs/app/web/src/pages/role/models/role.js').then(
                      m => {
                        return { namespace: 'role', ...m.default };
                      },
                    ),
                  ],
                  component: () => import('../role'),
                })
              : require('../role').default,
            name: '角色管理',
            icon: 'user-circle-o',
            exact: true,
            _title: '系统管理',
            _title_default: '四川省农业信贷智能担保综合管理平台',
          },
          {
            path: '/system/auth',
            component: __IS_BROWSER
              ? _dvaDynamic({
                  app: require('@tmp/dva').getApp(),
                  models: () => [
                    import('D:/work/bank/nodejs/app/web/src/pages/auth/model.js').then(
                      m => {
                        return { namespace: 'model', ...m.default };
                      },
                    ),
                  ],
                  component: () => import('../auth'),
                })
              : require('../auth').default,
            name: '权限管理',
            icon: 'lock',
            exact: true,
            _title: '系统管理',
            _title_default: '四川省农业信贷智能担保综合管理平台',
          },
          {
            path: '/system/dictionary',
            component: __IS_BROWSER
              ? _dvaDynamic({
                  app: require('@tmp/dva').getApp(),
                  models: () => [
                    import('D:/work/bank/nodejs/app/web/src/pages/dictionary/model.js').then(
                      m => {
                        return { namespace: 'model', ...m.default };
                      },
                    ),
                  ],
                  component: () => import('../dictionary'),
                })
              : require('../dictionary').default,
            name: '数据字典',
            icon: 'book',
            exact: true,
            _title: '系统管理',
            _title_default: '四川省农业信贷智能担保综合管理平台',
          },
          {
            path: '/system/logs',
            component: __IS_BROWSER
              ? _dvaDynamic({
                  app: require('@tmp/dva').getApp(),
                  models: () => [
                    import('D:/work/bank/nodejs/app/web/src/pages/logs/model.js').then(
                      m => {
                        return { namespace: 'model', ...m.default };
                      },
                    ),
                  ],
                  component: () => import('../logs'),
                })
              : require('../logs').default,
            name: '操作日志',
            icon: 'paw',
            exact: true,
            _title: '系统管理',
            _title_default: '四川省农业信贷智能担保综合管理平台',
          },
          {
            component: () =>
              React.createElement(
                require('D:/work/bank/nodejs/node_modules/umi-build-dev/lib/plugins/404/NotFound.js')
                  .default,
                { pagesPath: 'src/pages', hasRoutesInConfig: true },
              ),
            _title: '四川省农业信贷智能担保综合管理平台',
            _title_default: '四川省农业信贷智能担保综合管理平台',
          },
        ],
        _title: '系统管理',
        _title_default: '四川省农业信贷智能担保综合管理平台',
      },
      {
        path: '/exception/403',
        component: __IS_BROWSER
          ? _dvaDynamic({
              component: () => import('../exception/403'),
            })
          : require('../exception/403').default,
        hide: true,
        exact: true,
        _title: '四川省农业信贷智能担保综合管理平台',
        _title_default: '四川省农业信贷智能担保综合管理平台',
      },
      {
        path: '/exception/500',
        component: __IS_BROWSER
          ? _dvaDynamic({
              component: () => import('../exception/500'),
            })
          : require('../exception/500').default,
        exact: true,
        _title: '四川省农业信贷智能担保综合管理平台',
        _title_default: '四川省农业信贷智能担保综合管理平台',
      },
      {
        component: __IS_BROWSER
          ? _dvaDynamic({
              component: () => import('../404'),
            })
          : require('../404').default,
        exact: true,
        _title: '四川省农业信贷智能担保综合管理平台',
        _title_default: '四川省农业信贷智能担保综合管理平台',
      },
      {
        component: () =>
          React.createElement(
            require('D:/work/bank/nodejs/node_modules/umi-build-dev/lib/plugins/404/NotFound.js')
              .default,
            { pagesPath: 'src/pages', hasRoutesInConfig: true },
          ),
        _title: '四川省农业信贷智能担保综合管理平台',
        _title_default: '四川省农业信贷智能担保综合管理平台',
      },
    ],
    _title: '四川省农业信贷智能担保综合管理平台',
    _title_default: '四川省农业信贷智能担保综合管理平台',
  },
  {
    component: () =>
      React.createElement(
        require('D:/work/bank/nodejs/node_modules/umi-build-dev/lib/plugins/404/NotFound.js')
          .default,
        { pagesPath: 'src/pages', hasRoutesInConfig: true },
      ),
    _title: '四川省农业信贷智能担保综合管理平台',
    _title_default: '四川省农业信贷智能担保综合管理平台',
  },
];
window.g_routes = routes;
const plugins = require('umi/_runtimePlugin');
plugins.applyForEach('patchRoutes', { initialValue: routes });

export { routes };

export default class RouterWrapper extends React.Component {
  unListen() {}

  constructor(props) {
    super(props);

    // route change handler
    function routeChangeHandler(location, action) {
      plugins.applyForEach('onRouteChange', {
        initialValue: {
          routes,
          location,
          action,
        },
      });
    }
    this.unListen = history.listen(routeChangeHandler);
    routeChangeHandler(history.location);
  }

  componentWillUnmount() {
    this.unListen();
  }

  render() {
    const props = this.props || {};
    return <Router history={history}>{renderRoutes(routes, props)}</Router>;
  }
}
